home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / basic / amiblitz_ful.lha / AmiBlitz2 / Examples / GraphicsCard / blits.ab2 < prev    next >
Encoding:
Text File  |  2002-05-23  |  2.8 KB  |  94 lines

  1. vsyncon=0   ;switch on if you want vsync (no tearing visible)
  2. #scrolling=0 ;set to 1 if you check speed when you scroll the background
  3. optimize 7;
  4. ;A little demo of moving things using the Blit command...
  5. ; the image.res must inlcude in compileroptions to use this functions
  6. WBStartup
  7. ;create a 'ball' type variable
  8. ;
  9. NEWTYPE.ball
  10. x.q
  11. y
  12. xs
  13. ys
  14. End NEWTYPE
  15.  DEFTYPE.l
  16. ;dimension a 'List' of 'balls'
  17.  
  18.  
  19. Dim List balls.ball(30)
  20. !image_include
  21. !screen_ {0,"","ram:prefsfile",1}:If scr\id=0 Then End  ;for display
  22. Window 0,0,0,scr\width,scr\height,$800,"",0,1
  23. succ=image_load  {1,"amiga1000.jpg"}
  24. succ=image_load  {0,"ball.iff"}
  25.  
  26. image_blit{1,0,0} ;to set the palette for 8bit screens
  27.  InitShape 0,16,16,2
  28.  WPointer 0          ;set a unvisible mousepointer
  29. !screen_ {1,"","ram:prefsfile",0}:If scr\id=0 Then End  ;for render
  30.  ;a second screen for doublebuffer
  31. Window 1,0,0,scr\width,scr\height,$800,"",0,1 ;second window
  32. !screen_ {2,"","ram:prefsfile",0}:If scr\id=0 Then End ;screen for background
  33.  
  34. Window 2,0,0,scr\width,scr\height,$800,"",0,1 ;window to store backgroundimage
  35. image_blit{1,0,0}  ;blit the backgroundimage in window
  36. ;keep adding items to list until list full
  37. ;
  38. While AddLast(balls())
  39.   balls()\x=Rnd(scr\width-30)+15,Rnd(scr\height-30)+15,(Rnd-.5)*20+1,(Rnd-.5)*20+1
  40. Wend
  41.  
  42.   ShowScreen 0
  43.  
  44. ;while mouse button not hit..
  45. ;
  46. While Joyb(0)=0
  47.  
  48.   If vsyncon VWait        ;can enable if you dont like tearing
  49.                           ;but most time this is unvisibly
  50.   Use Screen 1 ;copy all from screen 1 to window 0
  51.   Use Window 0
  52.   image_blitblock{0}
  53.   CNIF #scrolling>0
  54.   Use Window 2
  55.   WScroll 0,0,scr\width,scr\height,1,1 ;scroll the background
  56.   CEND
  57.   Use Window 1 ;set the renderwindow to 1
  58.   ;start at first item in list
  59.   ;
  60.   ResetList balls()
  61.   ;WCls
  62.   Use Screen 2         ;use the backgroundimage from screen 2
  63.                        ;screennum is source
  64.                        ;windowsnum is destination
  65.   image_blitblock{0}     ;blit whole backgroundimage
  66.   WLocate 220,55
  67.   If res<5 Then res=5
  68.   CNIF #scrolling=0    ;use textbackgroundcolor when scroll to read fps better
  69.   WJam 0               ;dont use textbackgroundcolor
  70.   CEND
  71.   NPrint "fps  ",50/(res LSR 2),"    ",num
  72.  
  73.   ;wait for vertical blank
  74.   ;
  75.   ;Delay_(1)
  76.  
  77.   ;while more items to come...
  78.   ;
  79.   While NextItem(balls())
  80.     balls()\x+balls()\xs
  81.     balls()\y+balls()\ys
  82.     ;reverse direction if ball gets to edge of bitmap
  83.     ;
  84.     If balls()\x<10 OR balls()\x>scr\width Then balls()\xs=-balls()\xs
  85.     If balls()\y<10 OR balls()\y>scr\height Then balls()\ys=-balls()\ys
  86.     image_blitmask {0,balls()\x,balls()\y,1} ;draw balls
  87. 'l1    BTST #6,$dff016
  88.     BEQ 'l1
  89.   Wend
  90.   count+1
  91.   If count=4 Then count=0:res=Timer:ResetTimer
  92. Wend
  93. End  ;important allow autofree
  94.